package com.ruoyi.project.bas.traycode.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.bas.traycode.mapper.BasTraycodeMapper;
import com.ruoyi.project.bas.traycode.domain.BasTraycode;
import com.ruoyi.project.bas.traycode.service.IBasTraycodeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 托盘条码信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-04-04
 */
@Service
public class BasTraycodeServiceImpl implements IBasTraycodeService 
{
    @Autowired
    private BasTraycodeMapper basTraycodeMapper;

    /**
     * 查询托盘条码信息
     * 
     * @param id 托盘条码信息主键
     * @return 托盘条码信息
     */
    @Override
    public BasTraycode selectBasTraycodeById(Integer id)
    {
        return basTraycodeMapper.selectBasTraycodeById(id);
    }

    /**
     * 查询托盘条码信息列表
     * 
     * @param basTraycode 托盘条码信息
     * @return 托盘条码信息
     */
    @Override
    public List<BasTraycode> selectBasTraycodeList(BasTraycode basTraycode)
    {
        return basTraycodeMapper.selectBasTraycodeList(basTraycode);
    }

    /**
     * 新增托盘条码信息
     * 
     * @param basTraycode 托盘条码信息
     * @return 结果
     */
    @Override
    public int insertBasTraycode(BasTraycode basTraycode)
    {
        for(int i=basTraycode.getBeginCode();i<basTraycode.getBeginCode()+basTraycode.getBeginCount();i++){
            String traycode=basTraycode.gettHead()+String.format("%07d",i);
            basTraycode.setTrayCode(traycode);

            basTraycodeMapper.insertBasTraycode(basTraycode);

        }
        return basTraycodeMapper.insertBasTraycode(basTraycode);
    }

    /**
     * 修改托盘条码信息
     * 
     * @param basTraycode 托盘条码信息
     * @return 结果
     */
    @Override
    public int updateBasTraycode(BasTraycode basTraycode)
    {
        return basTraycodeMapper.updateBasTraycode(basTraycode);
    }

    /**
     * 批量删除托盘条码信息
     * 
     * @param ids 需要删除的托盘条码信息主键
     * @return 结果
     */
    @Override
    public int deleteBasTraycodeByIds(String ids)
    {
        return basTraycodeMapper.deleteBasTraycodeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除托盘条码信息信息
     * 
     * @param id 托盘条码信息主键
     * @return 结果
     */
    @Override
    public int deleteBasTraycodeById(Integer id)
    {
        return basTraycodeMapper.deleteBasTraycodeById(id);
    }

    @Override
    public int selectHeadCount(String tHead) {
        return basTraycodeMapper.selectHeadCount(tHead);
    }

    @Override
    public void updateStatus(String trayCode) {
        basTraycodeMapper.updateTrayCodeStatus(trayCode);
    }
}
